﻿using System;
using System.Web;
using System.Web.UI.WebControls;

using OctoOS;
using OctoOS.UI;

public partial class __deleteSection : OOSPage
{
	class PathInfo
	{
		[PathInfoMember(0)]
		[RangeValidator(1, Int64.MaxValue)]
		[IntegerBase(64)]
		internal long ArticleID = 0;

		[PathInfoMember(1)]
		[RangeValidator(1, Int64.MaxValue)]
		internal long PageID = 0;

		[PathInfoMember(2)]
		[RangeValidator(1, Int64.MaxValue)]
		internal long SectionID = 0;
	}

	PathInfo _pathInfo;

	protected void Page_Init(object sender, EventArgs e)
	{
		_pathInfo = EnablePathInfo<PathInfo>();
	}

    protected void Page_Load(object sender, EventArgs e)
    {
		PageTitle = Resources.Main.deleteSection_Title;

		Article article = ApiService.GetArticle(OOSRequest.Current, _pathInfo.ArticleID);

		if(!OOSRequest.Current.IsModerator &&
				article.UserID != OOSRequest.Current.UserID)
		{
			throw new HttpException();
		}

		var section = article.GetSection(_pathInfo.PageID, _pathInfo.SectionID);
		if(section == null)
			throw new ApplicationException();

		deleteMsg.SetContent(String.Format(Resources.Main.shared_DeleteSection, section.Title));
		deleteMsg.AddSubmit(Resources.Main.shared_Yes, YesBtn_Submit);
		deleteMsg.AddCancel(Resources.Main.shared_No, Urls.GetEditArticle(_pathInfo.ArticleID));
    }

	protected void YesBtn_Submit(object sender, EventArgs e)
	{
		ApiService.DeleteSection(OOSRequest.Current, _pathInfo.ArticleID,
			_pathInfo.PageID, _pathInfo.SectionID);

		Response.Redirect(Urls.GetEditArticle(_pathInfo.ArticleID));
	}
}